package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.unit.DataUnit;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//游记推荐
@Setter
@Getter
public class TravelCommend {
    public static final int TYPT_WEEK = 0; //每周推荐
    public static final int TYPT_MONTH = 1;//每月推荐
    public static final int TYPT_STRATEGY = 2;//推荐攻略
    private Long id;  //id

    private Travel travel; //被推荐的文章

    private String title; //推荐的标题

    private String subTitle;//推荐的副标题

    private String coverUrl;//推荐的封面
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date schedule;//推荐的日期

    private int type;//推荐的类型

    public String getTypeDisplay(){
        if (type==TYPT_WEEK){
            return "每周推荐";
        }else if (type==TYPT_MONTH){
            return "每月推荐";
        }else if (type==TYPT_STRATEGY){
            return "攻略推荐";
        }
        return "";
    }

    //编辑框的回显
    public String getJsonString(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        if (travel!=null){
        map.put("travelId",travel.getId());
        }
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("schedule", DateUtil.date2string(schedule,"yyyy-MM-dd"));
        map.put("type",type);
        map.put("coverUrl",coverUrl);
        return JSONUtil.toJSONString(map);
    }

}